package server

import (
	"github.com/go-kratos/kratos/contrib/registry/etcd/v2"
	"github.com/go-kratos/kratos/v2/registry"
	"github.com/google/wire"
	"ra-match-online/app/user/service/internal/conf"

	etcdclient "go.etcd.io/etcd/client/v3"
)

// ProviderSet is server providers.
var ProviderSet = wire.NewSet(NewGRPCServer, NewRegistrar)

func NewRegistrar(conf *conf.Registry) registry.Registrar {
	if conf.Etcd.Enable {
		client, err := etcdclient.New(etcdclient.Config{
			Endpoints: conf.Etcd.Address,
		})
		if err != nil {
			panic(err)
		}
		return etcd.New(client)
	}
	return nil
}
